package com.wenjie.controller.sys;

import cn.hutool.json.JSONObject;
import com.wenjie.original.entity.SysDbEnum;
import com.wenjie.original.entity.vo.SysDbField.SysDbFieldByAddEnumsVo;
import com.wenjie.original.entity.vo.SysDbField.SysDbFieldBySelEnumsVo;
import com.wenjie.original.entity.vo.SysDbField.SysDbFieldUpOrAddVo;
import com.wenjie.original.entity.vo.SysDbField.SysDbFieldVo;
import com.wenjie.original.service.ISysDbFieldService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api("字段映射")
@RestController
@RequestMapping("/api/sysDbField")
public class SysDbFieldController {

    @Autowired
    private ISysDbFieldService sysDbFieldService;


    @ApiOperation("查询字段的枚举值")
    @PostMapping("/listEnums")
    public List<SysDbEnum> listEnums(@RequestBody @Validated SysDbFieldBySelEnumsVo sysDbFieldBySelEnumsVo) {
        return sysDbFieldService.listEnums(sysDbFieldBySelEnumsVo);
    }


    @ApiOperation("查询字段的枚举值")
    @PostMapping("/AllEnums")
    public JSONObject AllEnums() {
        return sysDbFieldService.AllEnums();
    }


    @ApiOperation("查询接口")
    @PostMapping("/list")
    public List<SysDbFieldVo.ResVo> list(@RequestBody @Validated Long sysDbTableId) {
        return sysDbFieldService.cusListAll(sysDbTableId);
    }

    @ApiOperation("添加接口")
    @PostMapping("/add")
    public void add(@RequestBody @Validated SysDbFieldUpOrAddVo.AddVo addVo) {
        sysDbFieldService.save(addVo);
    }

    @ApiOperation("修改接口")
    @PostMapping("/up")
    public void up(@RequestBody @Validated SysDbFieldUpOrAddVo.UpVo upVo) {
        sysDbFieldService.cusUpdateById(upVo);
    }

    @ApiOperation("删除接口")
    @PostMapping("/del")
    public void del(@RequestBody @Validated Long sysDbFieldId) {
        sysDbFieldService.cusRemoveById(sysDbFieldId);
    }

    @ApiOperation("同步字段接口")
    @PostMapping("/sync")
    public void sync(@RequestBody JSONObject jsonObject) {
        sysDbFieldService.sync(jsonObject.getLong("sysDbTableId"), jsonObject.getStr("fieldName"));
    }

    @ApiOperation("同步全部字段接口")
    @PostMapping("/syncAll")
    public void syncAll(@RequestBody @Validated Long sysDbTableId) {
        sysDbFieldService.syncAll(sysDbTableId);
    }


    @ApiOperation("保存字段枚举数据")
    @PostMapping("/saveEnums")
    public void addEnums(@RequestBody @Validated SysDbFieldByAddEnumsVo sysDbFieldByAddEnumsVo) {
        sysDbFieldService.addEnums(sysDbFieldByAddEnumsVo);
    }


}
